13/01/2021

Schedule

  1. Working in different contexts: RStudio Projects
  2. Dynamic document generation: RMarkdown
  3. Version control: Git + GitHub
  4. Environment management: renv
  5. Containerization: Docker
  6. Start collaborating

0. Kudos

1. Working in different contexts: RStudio Projects - What & Why?

  • What it does:
    • Allows to work in multiple different contexts (projects), e.g. one for each experiment
    • Each project is own working directory, workspace, history, and source documents
    • Each project is associated with a folder on your computer (= working directory)
  • Why it helps:
    • Have a separate, shareable working environment for each experiment
    • Keep all the files associated with a project together — data, scripts, results, figures
    • Work on multiple projects at once, each associated with its packages (and package versions), loaded data, etc.
    • Use only relative paths
    • Necessary basis for version control

1. Working in different contexts: RStudio Projects – How?

  • In RStudio: File > New Project > …

1. Working in different contexts: RStudio Projects – Version 1: Create new project

1. Working in different contexts: RStudio Projects – Version 1: Create new project

1. Working in different contexts: RStudio Projects – Version 1: Create new project

1. Working in different contexts: RStudio Projects – Version 2: Create from existing directory

1. Working in different contexts: RStudio Projects – Version 3: Create from version control (Git)

1. Working in different contexts: RStudio Projects – Version 3: Create from version control (Git)

1. Working in different contexts: RStudio Projects – Open and manage projects

1. Working in different contexts: RStudio Projects – Open and manage projects

1. Working in different contexts: RStudio Projects – Troubleshooting

  • If necessary

2. Dynamic document generation: RMarkdown - What & Why?

  • What it does:
    • Creates dynamic documents with embedded chunks of code (R, python, Julia, stan, …), computed results , written text etc. (= LaTex)
    • Markdown-files can be exported to documents (docx, rtf), presentations, pdfs, or websites (html) e.g using the knitr (Xie, 2015, 2020) and tinytex (Xie, 2015, 2020; for pdfs)
    • R code is dynamically rendered, and can be given in separate chunks (’’‘{r}’’‘) or inline (’ r … ’)
  • Why it helps:
    • Simple language (\(\neq\) LaTex)
    • Integrates directly with statistical software (R Studio)
    • Saves code and output in one file
    • Reduces copy&paste errors: reported results consistent with actual results

2. Dynamic document generation: RMarkdown - How?

2. Dynamic document generation: RMarkdown - Troubleshooting

  • If necessary

3. Version control: Git + GitHub - What & Why?

  • What it does:
  • Why it helps:

3. Version control: Git + GitHub – How?

3. Version control: Git + GitHub - Troubleshooting

  • If necessary

4. Environment management: renv

4. renv – What & Why?

  • What it does:
    • Creates a project-specific library of packages in the project folder
    • Overwrites install.packages() to install packages there
    • Keeps track of package versions in the renv.lock file
  • Why it helps:
    • Keeps package versions untouched by other projects
    • Allows you to revert to the previous state when an update has broken your analysis
    • Makes it easier to share package versions with your collaborators (e.g., via GitHub)

4. renv – How?

  1. Install the renv package: install.packages(renv)
  2. Initialize your project library: renv::init()
  3. Install and update your packages as usual: install.packages("pkgname")
  4. Save the current state of the project library: renv::snapshot()
  5. Revert to a previous state if an update caused problems: renv::restore()

You can skip step #2 if you select “Use renv with this project” during project creation.

4. renv – Troubleshooting

  • If necessary

5. Containerization: Docker

5. Docker – What & Why?

  • What it does:
  • Why it helps:

5. Docker – How?

5. Docker – Troubleshooting

  • If necessary

6. Start colaborating